package com.r2coding.music.api;

import com.r2coding.common.util.Result;
import com.r2coding.music.entity.RegionEntity;
import com.r2coding.music.service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author:98k灬
 * @since:2022/05/22 18:10
 **/
@RestController
@RequestMapping("/api/region")
public class ApiRegionController {
    @Autowired
    RegionService regionService;

    /**
     * 获取地区列表
     *
     * @return 统一响应体
     */
    @GetMapping("/list")
    public Result list() {
        List<RegionEntity> list = regionService.list();
        return Result.ok(list);
    }

    /**
     * 查询地区详情
     *
     * @param id 地区id
     * @return 统一响应体
     */
    @GetMapping("/info/{id}")
    public Result info(@PathVariable("id") Integer id) {
        RegionEntity region = regionService.getById(id);
        return Result.ok(region);
    }
}
